package com.hjxr.xmgl.web.controller;

import java.util.List;

import com.hjxr.framework.web.domain.AjaxResult;
import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.page.TableDataInfo;
import com.hjxr.xmgl.web.domain.QuotaEarlyWarning;
import com.hjxr.xmgl.web.service.IQuotaEarlyWarningService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;


/**
 * 预警指标配置Controller
 *
 * @author hjxr
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/system/warning")
public class QuotaEarlyWarningController extends BaseController
{
    @Autowired
    private IQuotaEarlyWarningService quotaEarlyWarningService;

    /**
     * 查询预警指标配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuotaEarlyWarning quotaEarlyWarning)
    {
        startPage();
        List<QuotaEarlyWarning> list = quotaEarlyWarningService.selectQuotaEarlyWarningList(quotaEarlyWarning);
        return getDataTable(list);
    }

    /**
     * 导出预警指标配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:warning:export')")
    @Log(title = "预警指标配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuotaEarlyWarning quotaEarlyWarning)
    {
        List<QuotaEarlyWarning> list = quotaEarlyWarningService.selectQuotaEarlyWarningList(quotaEarlyWarning);
        ExcelUtil<QuotaEarlyWarning> util = new ExcelUtil<QuotaEarlyWarning>(QuotaEarlyWarning.class);
        return util.exportExcel(list, "warning");
    }

    /**
     * 获取预警指标配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:warning:query')")
    @GetMapping(value = "/{ewId}")
    public AjaxResult getInfo(@PathVariable("ewId") String ewId)
    {
        return AjaxResult.success(quotaEarlyWarningService.selectQuotaEarlyWarningById(ewId));
    }

    /**
     * 新增预警指标配置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:add')")
    @Log(title = "预警指标配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuotaEarlyWarning quotaEarlyWarning)
    {
        return toAjax(quotaEarlyWarningService.insertQuotaEarlyWarning(quotaEarlyWarning));
    }

    /**
     * 修改预警指标配置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:edit')")
    @Log(title = "预警指标配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuotaEarlyWarning quotaEarlyWarning)
    {
        return toAjax(quotaEarlyWarningService.updateQuotaEarlyWarning(quotaEarlyWarning));
    }

    /**
     * 删除预警指标配置
     */
    @PreAuthorize("@ss.hasPermi('system:warning:remove')")
    @Log(title = "预警指标配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ewIds}")
    public AjaxResult remove(@PathVariable String[] ewIds)
    {
        return toAjax(quotaEarlyWarningService.deleteQuotaEarlyWarningByIds(ewIds));
    }
}
